jetcrab\vm\types/
names.rs1use serde::{Deserialize, Serialize};
2use std::fmt;
3
4#[derive(Debug, Clone, PartialEq, Eq, Hash, Serialize, Deserialize)]
5pub struct VariableName(String);
6
7impl VariableName {
8 pub fn new(name: String) -> Self {
9 Self(name)
10 }
11
12 pub fn as_str(&self) -> &str {
13 &self.0
14 }
15
16 pub fn as_string(&self) -> String {
17 self.0.clone()
18 }
19
20 pub fn is_empty(&self) -> bool {
21 self.0.is_empty()
22 }
23
24 pub fn len(&self) -> usize {
25 self.0.len()
26 }
27}
28
29impl From<String> for VariableName {
30 fn from(name: String) -> Self {
31 Self(name)
32 }
33}
34
35impl From<&str> for VariableName {
36 fn from(name: &str) -> Self {
37 Self(name.to_string())
38 }
39}
40
41impl From<VariableName> for String {
42 fn from(name: VariableName) -> Self {
43 name.0
44 }
45}
46
47impl fmt::Display for VariableName {
48 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
49 write!(f, "{}", self.0)
50 }
51}
52
53impl AsRef<str> for VariableName {
54 fn as_ref(&self) -> &str {
55 &self.0
56 }
57}
58
59impl std::ops::Deref for VariableName {
60 type Target = str;
61
62 fn deref(&self) -> &Self::Target {
63 &self.0
64 }
65}
66
67#[derive(Debug, Clone, PartialEq, Eq, Hash, Serialize, Deserialize)]
68pub struct FunctionName(String);
69
70impl FunctionName {
71 pub fn new(name: String) -> Self {
72 Self(name)
73 }
74
75 pub fn as_str(&self) -> &str {
76 &self.0
77 }
78
79 pub fn as_string(&self) -> String {
80 self.0.clone()
81 }
82
83 pub fn is_empty(&self) -> bool {
84 self.0.is_empty()
85 }
86
87 pub fn len(&self) -> usize {
88 self.0.len()
89 }
90}
91
92impl From<String> for FunctionName {
93 fn from(name: String) -> Self {
94 Self(name)
95 }
96}
97
98impl From<&str> for FunctionName {
99 fn from(name: &str) -> Self {
100 Self(name.to_string())
101 }
102}
103
104impl From<FunctionName> for String {
105 fn from(name: FunctionName) -> Self {
106 name.0
107 }
108}
109
110impl fmt::Display for FunctionName {
111 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
112 write!(f, "{}", self.0)
113 }
114}
115
116impl AsRef<str> for FunctionName {
117 fn as_ref(&self) -> &str {
118 &self.0
119 }
120}
121
122impl std::ops::Deref for FunctionName {
123 type Target = str;
124
125 fn deref(&self) -> &Self::Target {
126 &self.0
127 }
128}
129
130#[derive(Debug, Clone, PartialEq, Eq, Hash, Serialize, Deserialize)]
131pub struct ClassName(String);
132
133impl ClassName {
134 pub fn new(name: String) -> Self {
135 Self(name)
136 }
137
138 pub fn as_str(&self) -> &str {
139 &self.0
140 }
141
142 pub fn as_string(&self) -> String {
143 self.0.clone()
144 }
145
146 pub fn is_empty(&self) -> bool {
147 self.0.is_empty()
148 }
149
150 pub fn len(&self) -> usize {
151 self.0.len()
152 }
153}
154
155impl From<String> for ClassName {
156 fn from(name: String) -> Self {
157 Self(name)
158 }
159}
160
161impl From<&str> for ClassName {
162 fn from(name: &str) -> Self {
163 Self(name.to_string())
164 }
165}
166
167impl From<ClassName> for String {
168 fn from(name: ClassName) -> Self {
169 name.0
170 }
171}
172
173impl fmt::Display for ClassName {
174 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
175 write!(f, "{}", self.0)
176 }
177}
178
179impl AsRef<str> for ClassName {
180 fn as_ref(&self) -> &str {
181 &self.0
182 }
183}
184
185impl std::ops::Deref for ClassName {
186 type Target = str;
187
188 fn deref(&self) -> &Self::Target {
189 &self.0
190 }
191}
192
193#[derive(Debug, Clone, PartialEq, Eq, Hash, Serialize, Deserialize)]
194pub struct PropertyName(String);
195
196impl PropertyName {
197 pub fn new(name: String) -> Self {
198 Self(name)
199 }
200
201 pub fn as_str(&self) -> &str {
202 &self.0
203 }
204
205 pub fn as_string(&self) -> String {
206 self.0.clone()
207 }
208
209 pub fn is_empty(&self) -> bool {
210 self.0.is_empty()
211 }
212
213 pub fn len(&self) -> usize {
214 self.0.len()
215 }
216}
217
218impl From<String> for PropertyName {
219 fn from(name: String) -> Self {
220 Self(name)
221 }
222}
223
224impl From<&str> for PropertyName {
225 fn from(name: &str) -> Self {
226 Self(name.to_string())
227 }
228}
229
230impl From<PropertyName> for String {
231 fn from(name: PropertyName) -> Self {
232 name.0
233 }
234}
235
236impl fmt::Display for PropertyName {
237 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
238 write!(f, "{}", self.0)
239 }
240}
241
242impl AsRef<str> for PropertyName {
243 fn as_ref(&self) -> &str {
244 &self.0
245 }
246}
247
248impl std::ops::Deref for PropertyName {
249 type Target = str;
250
251 fn deref(&self) -> &Self::Target {
252 &self.0
253 }
254}
255
256#[derive(Debug, Clone, PartialEq, Eq, Hash, Serialize, Deserialize)]
257pub struct ModuleName(String);
258
259impl ModuleName {
260 pub fn new(name: String) -> Self {
261 Self(name)
262 }
263
264 pub fn as_str(&self) -> &str {
265 &self.0
266 }
267
268 pub fn as_string(&self) -> String {
269 self.0.clone()
270 }
271
272 pub fn is_empty(&self) -> bool {
273 self.0.is_empty()
274 }
275
276 pub fn len(&self) -> usize {
277 self.0.len()
278 }
279}
280
281impl From<String> for ModuleName {
282 fn from(name: String) -> Self {
283 Self(name)
284 }
285}
286
287impl From<&str> for ModuleName {
288 fn from(name: &str) -> Self {
289 Self(name.to_string())
290 }
291}
292
293impl From<ModuleName> for String {
294 fn from(name: ModuleName) -> Self {
295 name.0
296 }
297}
298
299impl fmt::Display for ModuleName {
300 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
301 write!(f, "{}", self.0)
302 }
303}
304
305impl AsRef<str> for ModuleName {
306 fn as_ref(&self) -> &str {
307 &self.0
308 }
309}
310
311impl std::ops::Deref for ModuleName {
312 type Target = str;
313
314 fn deref(&self) -> &Self::Target {
315 &self.0
316 }
317}